<?php
include("./API.php");
tongji("ipcha");
$ip= $_REQUEST['ip'];//需要查询的IP地址
$type=$_REQUEST['type'];//返回格式，默认json可选text
require 'data/ipcha.php';
 
$addr = json_decode(file_get_contents('http://opendata.baidu.com/api.php?query="'.$ip.'&co=&resource_id=6006&t=1433920989928&ie=utf8&oe=utf-8&format=json'), true);

if($addr["data"][0]["location"]==null) {
  switch ($type) {
    case 'text':
     exit("ip有误或查询失败");
    default:
    exit(send(array(
    'code'=>1,
    'text'=>"ip有误或查询失败"
    )));  
}
}

switch ($type) {
    case 'text':
     exit($addr["data"][0]["location"]);
    default:
    exit(send(array(
    'code'=>1,
    'text'=>$addr["data"][0]["location"]
    )));
}
